package org.oc.qaq.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.oc.qaq.dto.UserDTO;
import org.oc.qaq.dto.UserPageQueryDTO;
import org.oc.qaq.dto.UserRegisterDTO;
import org.oc.qaq.result.Result;
import org.oc.qaq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/users")
@Tag(name = "用户管理相关api")
public class AdminUserController {

    @Autowired
    UserService userService;

    @Operation(summary = "用户添加接口")
    @PostMapping
    public Result<?> add(@RequestBody UserDTO userDTO) {
        userService.add(userDTO);
        return Result.success();
    }

    @Operation(summary = "用户信息更新接口")
    @PutMapping
    public Result<?> update(@RequestBody UserDTO user) {
        userService.update(user);
        return Result.success();
    }

    @Operation(summary = "用户删除接口")
    @DeleteMapping("/{uid}")
    public Result<?> delete(@PathVariable String uid) {
        userService.delete(uid);
        return Result.success();
    }

    @Operation(summary = "批量删除用户接口")
    @DeleteMapping("/deleteBatch")
    public Result<?> deleteBatch(@RequestBody List<String> ids) {
        userService.deleteBatch(ids);
        return Result.success();
    }

    @Operation(summary = "用户状态更改接口")
    @PutMapping("/status/{uid}/{status}")
    public Result<?> updateStatus(@PathVariable("uid") String uid
    , @PathVariable("status") int status) {
        userService.updateStatus(uid, status);
        return Result.success();
    }

    @Operation(summary = "用户查询接口")
    @GetMapping
    public Result<List<UserDTO>> list(UserPageQueryDTO queryDTO) {
        return userService.list(queryDTO);
    }
}
